package com.guigu.www.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.www.mapper.MenusMapper;
import com.guigu.www.pojo.Menus;
import com.guigu.www.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenusServiceImpl extends ServiceImpl<MenusMapper, Menus> implements MenusService {
    //获取Mapper
    @Autowired
    MenusMapper menusMapper;

    public List<Menus> queryByMenusFuId(List<Integer> roleid,Integer menusid){
       //查询父菜单
       List<Menus> list= menusMapper.queryByMenusFuId(roleid,menusid);

       return list;
    }

    //查询子菜单
    @Override
    public List<Menus> queryByMenusSon(List<Integer> roleid,int menuseg) {
        //查询子菜单
        List<Menus> listfu = menusMapper.queryByMenusFuId(roleid,menuseg);
        //查询子子菜单
        for (Menus menus : listfu) {
            List<Menus> listson = menusMapper.queryByMenusFuId(roleid,menus.getSeq());
            menus.setMenus(listson);
        }
        return listfu;
    }

    @Override
    public int querymaxseq() {
        return menusMapper.querymaxseq();
    }

    @Override
    public List<Menus> queryquanxianbyroleid(int roleid) {
        //查询所有的父菜单
        List<Menus> list=menusMapper.queryByMenusFuIds(0);
        for(Menus menus : list){
            List<Menus> son=menusMapper.queryByMenusFuIds(menus.getSeq());
            menus.setMenus(son);
        }
        //查询当前角色的菜单
        List<Integer> listroleid=menusMapper.queryquanxianbyroleid(roleid);
        for(Menus menus : list){
            if(listroleid.contains(menus.getId())){
                menus.setCheck(true);
            }
            for(Menus menus1 : menus.getMenus()){
                if(listroleid.contains(menus1.getId())){
                    menus1.setCheck(true);
                }
            }

        }
        return list;
    }

}
